
#游戏布局 10*10
#游戏颜色（1.2.3.4.5）


# 用来判断源头
successful_number = []
# 用来存储判断成功的值的个数

over_number = []
# 用来判断是否检测过

max_number = 0
# 用来存储相邻颜色最大区域的序号

max1 = 0
# 用来返回最大值的序号


def jiesuan(a):
    print(a)
    successful_number = []
    # 用来存储判断成功的值的个数

    over_number = []
    # 用来判断是否检测过

    max_number = 0
    # 用来存储相邻颜色最大区域的序号

    max1 = 0
    # 用来返回最大值的序号
    """从第一个到最后一个进行检测"""
    for x in range(1, 11):
        for y in range(1, 11):
            z = x * 100 + y
            if a[x][y] == 6:
                p = 1
            else:
                add(x, y, a[x][y], a, z, successful_number, over_number)

    return （max123(successful_number)-101）


def max123(successful_number):
    """结算出颜色最多的地方"""
    dict1 = {}  # 建立一个空字典
    s = set(successful_number)  # 列表去重
    for i in s:  # 遍历集合(也可以遍历列表，上面一行改成s = list(set(lt))即可)
        ct = successful_number.count(i)  # 检测i元素在lt列表中的次数（count函数）
        dict1[i] = ct  # 将i元素作为字典键+i元素的次数值作为值存到字典中
    try:
        return max(dict1, key=dict1.get)
    except:
        return 11


def add( x, y, zhi, a, z, successful_number, over_number):
    """判断一个地方有几个相邻颜色一样的"""
    if x * 100 + y in over_number:
        return
    else:
        over_number.append(x * 100 + y)
        if a[x - 1][y] == zhi:  # 检测上方的值
            if (x - 1) * 100 + y in over_number:
                p = 1
            else:
                successful_number.append(z)
                add((x - 1), y, zhi, a, z, successful_number, over_number)
        if a[x][y - 1] == zhi:  # 检测左方的值
            if x * 100 + y - 1 in over_number:
                p = 1
            else:
                successful_number.append(z)
                add(x, y - 1, zhi, a, z, successful_number, over_number)
        if a[x + 1][y] == zhi:  # 检测下方的值
            if (x + 1) * 100 + y in over_number:
                p = 1
            else:
                successful_number.append(z)
                add(x + 1, y, zhi, a, z, successful_number, over_number)
        if a[x][y + 1] == zhi:  # 检测右方的值
            if x * 100 + y + 1 in over_number:
                p = 1
            else:
                successful_number.append(z)
                add(x, y + 1, zhi, a, z, successful_number, over_number)




